# -*- coding:utf-8 -*-
#! python3
from facecat import *

#更新悬浮状态
#views:视图集合
def updateView(views):
	updateViewDefault(views)

#绘制视图
#view:视图
#paint:绘图对象
#clipRect:区域
def onPaint(view, paint, clipRect):
	onPaintDefault(view, paint, clipRect)
	if view.viewName == "TabPage":
		paint.drawLine("rgb(255,0,0)", 1, 0, 100, 100, 300, 300)
		paint.drawLine("rgb(255,0,255)", 1, 2, 100, 300, 300, 100)
	elif view.viewName == "TabPage2":
		paint.drawRect("rgb(0,255,0)", 1, 0, 100, 100, 200, 200)
		paint.fillRect("rgb(0,255,255)", 250, 250, 350, 350)
	elif view.viewName == "TabPage3":
		paint.drawEllipse("rgb(0,255,255)", 1, 0, 100, 100, 200, 200)
		paint.fillEllipse("rgb(255,0,255)", 250, 250, 350, 350)
	elif view.viewName == "TabPage4":
		paint.drawText("FaceCat", "rgb(255,0,0)", "Default,30", 100, 100)
	elif view.viewName == "TabPage5":
		drawPoints = []
		drawPoints.append(FCPoint(100, 100))
		drawPoints.append(FCPoint(150, 120))
		drawPoints.append(FCPoint(130, 200))
		drawPoints.append(FCPoint(200, 200))
		drawPoints.append(FCPoint(250, 220))
		paint.drawPolyline("rgb(255,0,0)", 1, 0, drawPoints)
	elif view.viewName == "TabPage6":
		drawPoints = []
		drawPoints.append(FCPoint(100, 100))
		drawPoints.append(FCPoint(150, 120))
		drawPoints.append(FCPoint(200, 200))
		drawPoints.append(FCPoint(150, 200))
		paint.fillPolygon("rgb(0,0,255)", drawPoints)

#绘制视图边线
#view:视图
#paint:绘图对象
#clipRect:区域
def onPaintBorder(view, paint, clipRect):
	onPaintBorderDefault(view, paint, clipRect)

#视图的鼠标移动方法
#view 视图
#mp 坐标
#buttons 按钮 0未按下 1左键 2右键
#clicks 点击次数
#delta 滚轮值
def onMouseMove(view, mp, buttons, clicks, delta):
	onMouseMoveDefault(view, mp, buttons, clicks, delta)
		
#视图的鼠标按下方法
#view 视图
#mp 坐标
#buttons 按钮 0未按下 1左键 2右键
#clicks 点击次数
#delta 滚轮值
def onMouseDown(view, mp, buttons, clicks, delta):
	onMouseDownDefault(view, mp, buttons, clicks, delta)

#视图的鼠标抬起方法
#view 视图
#mp 坐标
#buttons 按钮 0未按下 1左键 2右键
#clicks 点击次数
#delta 滚轮值
def onMouseUp(view, mp, buttons, clicks, delta):
	onMouseUpDefault(view, mp, buttons, clicks, delta)

#视图的鼠标点击方法
#view 视图
#firstTouch:是否第一次触摸 
#firstPoint:第一次触摸的坐标 
#secondTouch:是否第二次触摸 
#secondPoint:第二次触摸的坐标
#clicks 点击次数
def onClick(view, firstTouch, firstPoint, secondTouch, secondPoint, clicks):
	onClickDefault(view, firstTouch, firstPoint, secondTouch, secondPoint, clicks)

#视图的鼠标滚动方法
#view 视图
#mp 坐标
#buttons 按钮 0未按下 1左键 2右键
#clicks 点击次数
#delta 滚轮值
def onMouseWheel(view, mp, buttons, clicks, delta):
	onMouseWheelDefault(view, mp, buttons, clicks, delta)

appPaint = FCPaint() #创建绘图对象
appPaint.onPaint = onPaint 
appPaint.onPaintBorder = onPaintBorder
appPaint.onMouseDown = onMouseDown 
appPaint.onMouseMove = onMouseMove 
appPaint.onMouseUp = onMouseUp
appPaint.onMouseWheel = onMouseWheel
appPaint.onClick = onClick
appPaint.onUpdateView = updateView

#消息循环
def WndProc(hwnd,msg,wParam,lParam):
	return WndProcDefault(appPaint,hwnd,msg,wParam,lParam)

#初始化窗体
createMainWindow(appPaint, "facecat-py", WndProc)
current_file_path = os.path.abspath(__file__)
current_file_dir = os.path.dirname(current_file_path)
file0 = open(current_file_dir + "\\xml\\paintexample.xml", encoding="UTF-8")
xml = file0.read()
file0.close()
renderFaceCat(appPaint, xml)
showWindow(appPaint)